package com.link2room.ironhide.controller.api;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.ironhide.dto.param.manager.L2RAreaManagerParamDto;
import com.link2room.ironhide.dto.result.base.L2RCityDto;
import com.link2room.ironhide.dto.result.base.L2RCountryDto;
import com.link2room.ironhide.dto.result.base.L2RDistrictDto;
import com.link2room.ironhide.dto.result.base.L2RProvinceDto;
import com.link2room.ironhide.facade.IAreaManagerFacadeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.lang.reflect.ParameterizedType;

/**
 * Created by sss on 2016/10/11.
 */
@Api(tags = "区域")
@RestController
@RequestMapping("/api/Areas")
public class AreaApiController {
    @Resource
    private IAreaManagerFacadeService areaManagerFacadeService;

    @RequestMapping(value = "/Countries",method = RequestMethod.GET)
    public BaseResultDto<L2RCountryDto> countries() throws Exception {
        QueryResult<L2RCountryDto> l2rCountryResult = areaManagerFacadeService.listL2RCountry(new BaseL2rParamDto());
        BaseResultDto<L2RCountryDto> l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(l2rCountryResult);
        return l2rRs;
    }

    @ApiOperation(value="查询省份", response =L2RProvinceDto.class )
    @ApiImplicitParam(name = "countryCode", value = "国家代码", required = true, dataType = "String")
    @RequestMapping(value = "/Provinces",method = RequestMethod.GET)
    public BaseResultDto provinces(
            @RequestParam(name = "countryCode") String countryCode
    ) throws Exception {
        L2RAreaManagerParamDto l2RAreaManagerParamDto=new L2RAreaManagerParamDto();
        l2RAreaManagerParamDto.setCountryCode(countryCode);
        QueryResult<L2RProvinceDto> l2rProvinceResult = areaManagerFacadeService.listL2RProvice(l2RAreaManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(l2rProvinceResult);
        return l2rRs;
    }

    @RequestMapping(value = "/Cities",method = RequestMethod.GET)
    public BaseResultDto cities(
            @RequestParam(name = "provinceCode" ,required = true) Long provinceCode
    ) throws Exception {
        L2RAreaManagerParamDto l2RAreaManagerParamDto=new L2RAreaManagerParamDto();
        l2RAreaManagerParamDto.setProvinceCode(provinceCode);
        QueryResult<L2RCityDto> l2rCityResult = areaManagerFacadeService.listL2RCity(l2RAreaManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(l2rCityResult);
        return l2rRs;
    }

    @RequestMapping(value = "/Districts",method = RequestMethod.GET)
    public BaseResultDto districts(
            @RequestParam(name = "cityCode" ,required = true) Long cityCode
    ) throws Exception {
        L2RAreaManagerParamDto l2RAreaManagerParamDto=new L2RAreaManagerParamDto();
        l2RAreaManagerParamDto.setCityCode(cityCode);
        QueryResult<L2RDistrictDto> l2rDistrictResult = areaManagerFacadeService.listL2RDistrict(l2RAreaManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(l2rDistrictResult);
        return l2rRs;
    }

    @RequestMapping(value = "/Districts//District",method = RequestMethod.GET)
    public BaseResultDto district(
            @RequestParam(name = "districtCode") Long districtCode
    ) throws Exception {
        L2RAreaManagerParamDto l2RAreaManagerParamDto=new L2RAreaManagerParamDto();
        l2RAreaManagerParamDto.setDistrictCode(districtCode);
        L2RDistrictDto l2rDistrictResult = areaManagerFacadeService.getL2RDistrict(l2RAreaManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(l2rDistrictResult);
        return l2rRs;
    }
}
